package corbaServer;

import corbaServer.corba.ICorbaServerPOA;
import java.sql.SQLException;
import java.util.List;
import java.util.LinkedList;
import corbaServer.corba.RaceDTO;
import corbaServer.dao.CorbaRaceServerDAO;


public class CServer extends ICorbaServerPOA{

	private String name;
	 
	public RaceDTO[] getRaces() {
		CorbaRaceServerDAO pruebaDAO= new CorbaRaceServerDAO();
		pruebaDAO.setServerName(name);
		pruebaDAO.connect();
		List<RaceDO> raceList= new LinkedList<RaceDO>();
		try {
			raceList= pruebaDAO.getRaces();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		RaceDTO[] rDTO= new RaceDTO[raceList.size()];
		int i= 0;
		String name= "";
    	float dist;
    	String date= "";
    	int places;
		while(!raceList.isEmpty()){
			RaceDO aux= raceList.get(0);
			name= aux.getName();
			dist= aux.getDistance();
			date= aux.getDate();
			places= aux.getPlaces();
			RaceDTO race= new RaceDTO(name,dist,date,places);
			rDTO[i]= race;
			raceList.remove(0);
			i++;
		}
		
		return rDTO;
	}
	public String sayHello(){
		return "Hello world";
	}
	
	public void setName(String pname){
		this.name= pname;
	}
	
	public String getName(){
		return this.name;
	}
}
